#include<bits/stdc++.h>
using namespace std;
const int maxn=1000000+10;
int c[maxn],v[maxn];
long long dis[maxn];
int main(){
  //freopen("in", "r", stdin);
	int n,maxc;
	scanf("%d %d",&n,&maxc);
	for(int i=0;i<n;i++){
		//scanf("%d %d",&c[i],&v[i]);
		dis[i]=10000000000;
    c[i] = 1, v[i] = rand() % 10 + 1;
	}
	dis[n]=10000000000;
	dis[0]=0;
	for(int i=0;i<n;i++){
		for(int j=i+c[i];j<=n;j+=c[i]){
			if(dis[j]>dis[i]+1ll*v[i]*((j-i)/c[i]))
				dis[j]=dis[i]+1ll*v[i]*((j-i)/c[i]);
			if(j != n and c[i] == c[j] and v[j] <= v[i])
				break;
		}
	}
	cout<<c[3]<<endl;
	for(int i=1;i<=n;i++)
		printf("%lld ",dis[i]==10000000000?-1:dis[i]);
	return 0;
}

